﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Mvc;
using Entities;

namespace WebUI
{
    public class Common
    {
        public static string ConstructDelimitedString(IEnumerable<string> fileTypes)
        {
            if (fileTypes == null)
            {
                return "";
            }
            int count = fileTypes.Count();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < count; i++)
            {
                sb.Append(fileTypes.ElementAt(i));
                if (i < count - 1)
                {
                    sb.Append(',');
                }
            }

            return sb.ToString();
        }

        public static void PopulateFilter(FormCollection formCollection, FilterOperations filter)
        {
            filter.StartDate = string.IsNullOrEmpty(formCollection["StartDate"]) ? (DateTime?)null : DateTime.Parse(formCollection["StartDate"]);
            filter.EndDate = string.IsNullOrEmpty(formCollection["EndDate"]) ? (DateTime?)null : DateTime.Parse(formCollection["EndDate"]);
            filter.FileName = formCollection["FileName"];
            filter.FileType = formCollection["FileType"];
            filter.Host = formCollection["Host"];
            filter.User = formCollection["User"];
        }
    }
}